<script>
	import {
		socket
	} from './utils/socket.js'
	export default {
		onLaunch: function() {
			console.log('App Launch')
			this.webSocket = socket;
			this.url = "http://192.168.1.23:9090/";
			this.wurl = "ws://192.168.1.23:9090/websocket/";
			if (uni.getStorageSync("userId") != null && uni.getStorageSync("userId") != "") {
				if (uni.getStorageSync("enterprise").enterpriseId == 0||uni.getStorageSync("enterprise").enterpriseId == null) {
					uni.switchTab({
						url: "/pages/person/index/index"
					});
				} else {
					uni.setTabBarItem({
						index: 0,
						pagePath: "/pages/enterprise/index/index",
						success() {
							uni.switchTab({
								url: '/pages/enterprise/index/index'
							})
						}
					})
					uni.setTabBarItem({
						index: 1,
						pagePath: "/pages/enterprise/contacts/contacts"
					})
					uni.setTabBarItem({
						index: 2,
						pagePath: "/pages/enterprise/staging/staging",
						text: "工作台"
					})
					uni.setTabBarItem({
						index: 3,
						pagePath: "/pages/enterprise/my/my"
					})
				}
			}


			plus.push.addEventListener("click", function(msg) {
				if (msg.payload.team == null) {
					if (msg.content == "点击接听视频来电"&&(uni.getStorageSync("roomId") != null && uni.getStorageSync("roomId") !=0)) {
						setTimeout(() => {
							uni.navigateTo({
								url: "/pages/contact/vedio/vedio?friendId=" + msg.payload.id +
									"&friendName=" + msg.title +
									"&type=from" + "&channelId=" + msg.payload.channelId
							})
						}, 1000)
					} else if (msg.content == "点击接听语音来电"&&(uni.getStorageSync("roomId") != null && uni.getStorageSync("roomId") !=0)) {
						setTimeout(() => {
							uni.navigateTo({
								url: "/pages/contact/voice/voice?friendId=" + msg.payload.id +
									"&friendName=" + msg.title +
									"&type=from" + "&channelId=" + msg.payload.channelId
							})
						}, 1000)
					} else if (msg.content == "请求加您为好友") {
						setTimeout(() => {
							uni.navigateTo({
								url: "/pages/person/newFriend/newFriend"
							})
						}, 1000)
					} else if (msg.content == "已将您删除" || msg.content == "已拒绝您的好友申请") {

					} else {
						setTimeout(() => {
							uni.navigateTo({
								url: "/pages/contact/chat/chat?userId=" + msg.payload.id +
									"&userName=" + msg.title
							})
						}, 1000)
						console.log(msg)
					}
				} else {
					setTimeout(() => {
						uni.navigateTo({
							url: "/pages/contact/teamChat/teamChat?teamId=" + msg.payload.id + "&teamName=" + msg.title
						})
					}, 1000)
				}

			}, true)

		},
		onShow: function() {
			if (uni.getStorageSync("userId") != null && uni.getStorageSync("userId") != "") {
				socket.startWebSocket(this.wurl + uni.getStorageSync("userId") + '/' + uni
					.getStorageSync("token"));
			}
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
</style>